﻿package com.edward.action;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.edward.model.BVItem;
import com.edward.model.BVList;
import com.edward.service.BVListManager;
import com.opensymphony.xwork2.ActionSupport;

public class TestIreportAction extends ActionSupport{
	

	private static final long serialVersionUID = 7000562419610510545L;

	private List <BVItem> list;
	
	private Map<String,Object> map;
	
	private BVListManager bvListManager;
	
	private BVList bvList;
	
	private BVItem bvItem;
	

	public List<BVItem> getList() {
		return list;
	}

	public void setList(List<BVItem> list) {
		this.list = list;
	}
	
	public BVList getBvList() {
		return bvList;
	}

	public void setBvList(BVList bvList) {
		this.bvList = bvList;
	}

	public BVItem getBvItem() {
		return bvItem;
	}

	public void setBvItem(BVItem bvItem) {
		this.bvItem = bvItem;
	}


	
	public void setBvListManager(BVListManager bvListManager) {
		this.bvListManager = bvListManager;
	}

	public Map<String, Object> getMap() {
	        return map;
	    }
    public void setMap(Map<String, Object> map) {
	        this.map = map;
	    }





	public String execute() throws Exception {
		BVList b = bvListManager.getBVList(bvList.getId());
		int l = b.getAddress().length();
		list = b.getItems();
		map = testReflect(b);
		if(l>54){
			map.put("a4", " " + b.getAddress().substring(54, l));
			l = 54;
		}
		if(l>36){
			map.put("a3"," " +  b.getAddress().substring(36, l));
			l=36;
		}
		if(l>18){
			map.put("a2"," " +  b.getAddress().substring(18, l));
			l=18;
		}
			map.put("a1"," " +  b.getAddress().substring(0, l));
	
		return SUCCESS;
	}
	

	
	 public static Map<String,Object> testReflect(Object obj) {      
		  Map<String,Object> hashMap = new HashMap<String,Object>();      
		  try {      
		   Class<? extends Object> c = obj.getClass();      
		   Method m[] = c.getDeclaredMethods();      
		   for (int i = 0; i < m.length; i++) {      
		    if (m[i].getName().indexOf("get")==0) {      
		     hashMap.put(m[i].getName(), m[i].invoke(obj, new Object[0]));      
		    }      
		   }      
		  } catch (Throwable e) {      
		   System.err.println(e);      
		  }      
		  return hashMap;      
		 }   

	
	
	
	

}
